package ru.prototype.jforex;

import com.dukascopy.api.system.ClientFactory;
import com.dukascopy.api.system.IClient;
import com.dukascopy.api.system.ISystemListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * TODO
 *
 * @author Artemiy Stepanov (artem.omsk@gmail.com)
 * @version 1.0 (04.01.14)
 */
public class Hello {

    private static final Logger LOG = LoggerFactory.getLogger(Hello.class);

    private static final String JFOREX_URL = "https://www.dukascopy.com/client/demo/jclient/jforex.jnlp";
    private static final String JFOREX_LOGIN = "Medero89xD";
    private static final String JFOREX_PASSWORD = "qJuhH362";

    public static void main(String[] args) throws Exception {

        //get the instance of the IClient interface
        final IClient client = ClientFactory.getDefaultInstance();
        client.setSystemListener(new ISystemListener() {
            @Override
            public void onStart(long processId) {
                LOG.info("Strategy started");
            }

            @Override
            public void onStop(long processId) {
                LOG.info("Strategy stopped");
            }

            @Override
            public void onConnect() {
                LOG.info("Connected");

            }

            @Override
            public void onDisconnect() {
                LOG.info("Disconnected");
            }
        });
        LOG.info("Connecting...");
        //connect to the server using jnlp, user name and password
        client.connect(JFOREX_URL, JFOREX_LOGIN, JFOREX_PASSWORD);

        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        LOG.info("Is connected: " + client.isConnected());
        LOG.info("Disconnecting..");
        client.disconnect();
        LOG.info("Is connected: " + client.isConnected());
    }
}
